<?php

class ChangeController extends Controller {

	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	public $layout = '//layouts/column2';

	/**
	 * @return array action filters
	 */
	public function filters() {
		return array(
			'accessControl', // perform access control for CRUD operations
		);
	}

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules() {
		return array(
			array('allow', // allow admin user to perform 'admin' and 'delete' actions
				'actions' => array('my'),
				'roles' => array('sektion'),
			),
			array('allow', // allow admin user to perform 'admin' and 'delete' actions
				'actions' => array('open'),
				'roles' => array('admin'),
			),			
			array('deny', // deny all users
				'users' => array('*'),
			),
		);
	}

	/**
	 * List open changes from a section or canton user
	 */
	public function actionMy() {
		$attributeChanges = AttributeChange::model()->getOpenChangesByUser(Yii::app()->user->getId());
		$membershipChanges = MembershipChange::model()->getOpenChangesByUser(Yii::app()->user->getId());
		$this->render('my', array(
			'attributeChanges' => $attributeChanges,
			'membershipChanges' => $membershipChanges,
		));
	}


	/**
	 * List open changes the admin has to do
	 */
	public function actionOpen() {
		$attributeChanges = AttributeChange::model()->getOpenChanges();
		$membershipChanges = MembershipChange::model()->getOpenChanges();
		$this->render('open', array(
			'attributeChanges' => $attributeChanges,
			'membershipChanges' => $membershipChanges,
		));
	}
	


}
